package com.hfut.wxy.common.exception;


import com.hfut.wxy.common.response.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalException {

    @ExceptionHandler(WxyException.class)
    public Response runWxyHandler(Exception e){
        e.printStackTrace();
        String message = e.getMessage();
        if (message.equals("4001")){
            return Response.tokenException;
        }
        if (message.equals("4002")){
            return Response.tokenInvalid;
        }
        return Response.errorMsg(message);
    }

    @ExceptionHandler(Exception.class)
    public Response runHandler(Exception e){
        e.printStackTrace();
        return Response.error(e.getMessage());
    }
}
